//
//  LGPatientAttendStringEditCell.m
//  HeartDiseaseManage
//
//  Created by 1234 on 2023/11/2.
//  心电图诊断

#import "LGPatientAttendStringEditCell.h"
#import "LGCustomTextView.h"
@interface LGPatientAttendStringEditCell()<LGTextViewDelegate>
/**   */
@property (nonatomic , strong)UIView *baseView;
/**   */
@property (nonatomic , strong)UILabel *titleLabel;
/**   */
@property (nonatomic , strong)LGCustomTextView *contentTF;

@end

@implementation LGPatientAttendStringEditCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubView];
    }
    return  self;
}

-(void)setContent:(NSString *)content{
    _content = content;
    self.contentTF.content = content;
}

-(void)textViewDidEndEditing:(NSString *)content{
    if (self.delegate && [self.delegate respondsToSelector:@selector(mainInspectEditChanged:index:key:)]) {
        [self.delegate mainInspectEditChanged:@{@"content":content} index:0 key:@"report6"];
    }
}

-(void)textViewHeightChanged:(CGFloat)height{
    height = (height>viewPix(80))?height:viewPix(80);
    CGFloat contentHeight = self.contentTF.size.height;
    if(height != contentHeight){
        [self.contentTF mas_updateConstraints:^(MASConstraintMaker *make) {
            make.height.equalTo(@(height));
        }];
        [self.tableView beginUpdates];
        [self.tableView endUpdates];
    }
}


-(void)createSubView{
    self.clipsToBounds = YES;
    self.backgroundColor = [UIColor clearColor];
    self.contentView.backgroundColor = [UIColor clearColor];
    [self.contentView addSubview:self.baseView];
    [self.contentView addSubview:self.titleLabel];
    [self.contentView addSubview:self.contentTF];

    [self.baseView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.bottom.equalTo(self.contentView).offset(viewPix(16));
        make.top.right.equalTo(self.contentView).offset(-viewPix(16));
    }];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).offset(viewPix(10));
        make.left.equalTo(self.baseView).offset(viewPix(10));
    }];
    [self.contentTF mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.titleLabel.mas_right).offset(viewPix(8));
        make.top.equalTo(self.contentView).offset(viewPix(4));
        make.bottom.equalTo(self.contentView).offset(-viewPix(4));
        make.right.equalTo(self.baseView).offset(-viewPix(12));
        make.height.equalTo(@(viewPix(28)));
    }];
}


-(UIView *)baseView{
    if(!_baseView){
        _baseView = [UIView shadowViewWithColor:@"#B3C5D9" offset:CGSizeMake(0, 2) opacity:0.15 radius:10];
        _baseView.backgroundColor = [UIColor whiteColor];
    }
    return _baseView;
}

-(UILabel *)titleLabel{
    if(!_titleLabel){
        _titleLabel = [UILabel lableWithText:@"诊断" colorString:@"#666666" textFont:LGFont(13) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _titleLabel;
}

-(LGCustomTextView *)contentTF{
    if(!_contentTF){
        _contentTF = [LGCustomTextView textViewWithPlaceHolder:@"请输入" placeHolderColor:@"#999999" placeHolderFont:LGFont(13) textColor:@"#333333" textFont:LGFont(14) textAlignment:NSTextAlignmentLeft keyboard:UIKeyboardTypeDefault];
        _contentTF.layer.borderColor = [UIColor colorWithString:@"#E3E3E3"].CGColor;
        _contentTF.layer.borderWidth = 1;
        _contentTF.cornerRidus = 5;
        _contentTF.customDelegate = self;
        _contentTF.maxCount = 200;
    }
    return _contentTF;
}


@end
